package com.definity.toolkit.ui.util;

import java.text.NumberFormat;
import java.text.ParseException;

import javax.swing.text.MaskFormatter;

import com.definity.toolkit.ToolkitRuntimeException;
import com.definity.toolkit.i18n.Config;

public class MaskFactory {

	public static MaskFormatter getDateMask() {
		return getConfigMask("date.mask");
	}

	public static MaskFormatter getTimeMask() {
		return getConfigMask("time.mask");
	}

	public static MaskFormatter getPhoneMask() {
		return getConfigMask("phone.mask");
	}

	public static MaskFormatter getZipCodeMask() {
		return getConfigMask("zipCode.mask");
	}

	public static NumberFormat getCurrencyFormatter() {
		NumberFormat defaultFormat = NumberFormat.getNumberInstance();
		defaultFormat.setMaximumFractionDigits(2);
		defaultFormat.setMinimumFractionDigits(2);

		return defaultFormat;
	}
	
	public static MaskFormatter getConfigMask(String key) {
		try {
			return new MaskFormatter(Config.getProperty(key));
		} catch (ParseException e) {
			throw new ToolkitRuntimeException(e);
		}
	}
	
}
